package org.suyafei.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.suyafei.manager.ProductManager;
import org.suyafei.mapper.ProductMapper;
import org.suyafei.model.ProductDO;
import org.suyafei.service.ProductService;
import org.suyafei.utils.BeanUtil;
import org.suyafei.vo.ProductVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 宿某人
 * @Date: 2022/02/05/12:14 下午
 * @Description:
 */
@Service
@Slf4j
public class ProductServiceImpl implements ProductService {


    @Autowired
    private ProductManager productManager;
    @Override
    public List<ProductVO> list() {
        List<ProductDO> list = productManager.list();
        List<ProductVO> productVOList = list.stream().map(obj -> BeanUtil.beanProcess(obj, ProductVO.class)).collect(Collectors.toList());
        return productVOList;
    }

    @Override
    public ProductVO findDetail(long productId) {
        ProductDO productDetail = productManager.findDetailById(productId);
        ProductVO productVO = BeanUtil.beanProcess(productDetail, ProductVO.class);
        return productVO;
    }
}
